<template lang="jade">
div


  h-loader-full
        m-title(icon='add',name='人数统计（展示人数 = 真实人数+虚拟人数）')
        //- List
        table.list
          ml-header(data='真实人数,展示人数,虚拟人数,操作')
          tr
            td {{ real }}
            td {{ count }} 
            td
              input(type='text', v-model="vitrual")
            td
              button(@click="client_addvitrual()" ) 修改虚拟人数
        .command



  h-loader-full
        m-title(icon='add',name='聊天用户')
        //- List
        table.list
          ml-header(data='OPENID:6,头像,用户名,操作:13')
          tr(v-for='(v, i) in list')
            td {{v.uid}}
            td: img(:src="v.avatarUrl")
            td {{ v.name }}
            td
              button(@click="discuss_enjoin(v.uid)" v-if="enjoinlist.indexOf(v.uid) == -1") 禁言
              button(@click="discuss_unjoint(v.uid)" v-if="enjoinlist.indexOf(v.uid) > -1") 解除禁言
        .command




</template>



<script>
export default {
	data () {
		return {
      vitrual:0,
      list:{},
      enjoinlist:{},
      count:0,
      real:0,
      vitrual:0,
		}
	},
  mounted () {
    this.socket = io('wss://hixq.sock.sgboke.com?uid=0&name=0&avatarUrl=0');
    this.socket.on('userlist',(res) => {
      for (var i in res) {
        res[i]['name'] = this.UnicodeToUtf8(res[i]['name'])
      }
      this.list = res;
    })



    //获取递加当前人数
    this.socket.on('client_reset',(res) => {
      this.count = res.count;
      this.real = res.real;
      this.vitrual = res.vitrual;      
    })

    //获取禁言列表
    this.socket.on('discuss_enjoinlist',(res) => {
      this.enjoinlist = res.data;
    })


    this.socket.on('discuss_enjoin_ok',(res) => {
      alert("禁言成功");
    })
    this.socket.on('discuss_unjoint_ok',(res) => {
      alert("解除禁言成功");
    })


  },
	methods: {
    UnicodeToUtf8(str) {
      str = str.replace(/\\/g, "%");
      return unescape(str);
    },
    //禁言
    discuss_enjoin(uid){
      this.socket.emit('discuss_enjoin', {
        uid : uid
      });
    },
    //解除禁言
    discuss_unjoint(uid){
      this.socket.emit('discuss_unjoint', {
        uid : uid
      });
    },

    //修改虚拟人数
    client_addvitrual(){
      this.socket.emit('client_addvitrual', {
        vitrual : this.vitrual
      });
    },


	}
}
</script>
